package com.xja.controller;

import com.xja.model.dto.EvaluationDTO;
import com.xja.model.entity.Evaluation;
import com.xja.model.vo.resp.Result;
import com.xja.service.IEvaluationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 评测表 前端控制器
 * </p>
 *
 * @author caijg
 * @since 2025-06-08
 */
@RestController
@RequestMapping("/user/evaluate")
@RequiredArgsConstructor
@Tag(name = "健康测评模块")
@Slf4j
public class EvaluationController {

    private final IEvaluationService evaluationService;

    @Operation(summary = "健康测评")
    @PostMapping("/result")
    public Result<Evaluation> getResult(@RequestBody EvaluationDTO evaluationDTO) {
        log.info("用户作答完毕，开始健康测评...{}", evaluationDTO);
        Evaluation result = evaluationService.getResult(evaluationDTO);
        return Result.success(result);
    }

    @Operation(summary = "用户获取历史评测记录")
    @GetMapping("/history")
    public Result<List<Evaluation>> getHistory() {
        log.info("用户获取历史评测记录...");
        List<Evaluation> history = evaluationService.getHistory();
        return Result.success(history);
    }

    @Operation(summary = "用户删除历史评测记录")
    @PostMapping("/delete")
    public Result<Boolean> deleteHistory(@RequestBody ArrayList<String> ids) {
        log.info("删除用户历史评测记录...{}", ids);
        Boolean deleted = evaluationService.deleteHistory(ids);
        return Result.success(deleted);
    }
}
